import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/refund_model.dart';

RefundModel $RefundModelFromJson(Map<String, dynamic> json) {
  final RefundModel refundModel = RefundModel();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    refundModel.id = id;
  }
  final int? orderId = jsonConvert.convert<int>(json['order_id']);
  if (orderId != null) {
    refundModel.orderId = orderId;
  }
  final double? price = jsonConvert.convert<double>(json['price']);
  if (price != null) {
    refundModel.price = price;
  }
  final int? type = jsonConvert.convert<int>(json['type']);
  if (type != null) {
    refundModel.type = type;
  }
  final int? reason = jsonConvert.convert<int>(json['reason']);
  if (reason != null) {
    refundModel.reason = reason;
  }
  final String? refundContent = jsonConvert.convert<String>(json['refund_content']);
  if (refundContent != null) {
    refundModel.refundContent = refundContent;
  }
  final int? state = jsonConvert.convert<int>(json['state']);
  if (state != null) {
    refundModel.state = state;
  }
  final String? images = jsonConvert.convert<String>(json['images']);
  if (images != null) {
    refundModel.images = images;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    refundModel.createdAt = createdAt;
  }
  final List<RefundLogs>? logs = (json['logs'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<RefundLogs>(e) as RefundLogs).toList();
  if (logs != null) {
    refundModel.logs = logs;
  }
  return refundModel;
}

Map<String, dynamic> $RefundModelToJson(RefundModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['order_id'] = entity.orderId;
  data['price'] = entity.price;
  data['type'] = entity.type;
  data['reason'] = entity.reason;
  data['refund_content'] = entity.refundContent;
  data['state'] = entity.state;
  data['images'] = entity.images;
  data['created_at'] = entity.createdAt;
  data['logs'] = entity.logs?.map((v) => v.toJson()).toList();
  return data;
}

extension RefundModelExtension on RefundModel {
  RefundModel copyWith({
    int? id,
    int? orderId,
    double? price,
    int? type,
    int? reason,
    String? refundContent,
    int? state,
    String? images,
    String? createdAt,
    List<RefundLogs>? logs,
  }) {
    return RefundModel()
      ..id = id ?? this.id
      ..orderId = orderId ?? this.orderId
      ..price = price ?? this.price
      ..type = type ?? this.type
      ..reason = reason ?? this.reason
      ..refundContent = refundContent ?? this.refundContent
      ..state = state ?? this.state
      ..images = images ?? this.images
      ..createdAt = createdAt ?? this.createdAt
      ..logs = logs ?? this.logs;
  }
}

RefundLogs $RefundLogsFromJson(Map<String, dynamic> json) {
  final RefundLogs refundLogs = RefundLogs();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    refundLogs.id = id;
  }
  final int? refundId = jsonConvert.convert<int>(json['refund_id']);
  if (refundId != null) {
    refundLogs.refundId = refundId;
  }
  final int? type = jsonConvert.convert<int>(json['type']);
  if (type != null) {
    refundLogs.type = type;
  }
  final String? content = jsonConvert.convert<String>(json['content']);
  if (content != null) {
    refundLogs.content = content;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    refundLogs.createdAt = createdAt;
  }
  return refundLogs;
}

Map<String, dynamic> $RefundLogsToJson(RefundLogs entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['refund_id'] = entity.refundId;
  data['type'] = entity.type;
  data['content'] = entity.content;
  data['created_at'] = entity.createdAt;
  return data;
}

extension RefundLogsExtension on RefundLogs {
  RefundLogs copyWith({
    int? id,
    int? refundId,
    int? type,
    String? content,
    String? createdAt,
  }) {
    return RefundLogs()
      ..id = id ?? this.id
      ..refundId = refundId ?? this.refundId
      ..type = type ?? this.type
      ..content = content ?? this.content
      ..createdAt = createdAt ?? this.createdAt;
  }
}